{% extends "../base_public.html" %}
{% load custom_markdown %}
{% block content %}

<div class="container-fluid" style="width:90%;padding-left: 180px;">
      <table class="table table-bordered">
          <tr style="font-weight: bold;">
            <td>Worker</td>
            <!--<td>Broker</td>
            <td>Pool</td>
            <td>rusage</td> -->
            <td>clock</td>
            <td>pid</td>
            <td>total</td>
            <td>进程数</td>
            <td>查看详情</td>
            <td>调整进程池数目</td>
          </tr>

        {% for k,v in data.items %}
        <tr>
          <td><a href="/ansible/celery/{{ k }}">{{ k }}</a></td>
          <!--<td><pre>{{ v.broker|json_format }}</pre></td> 
            <td><pre>{{ v.pool|json_format }}</pre></td>
            <td><pre>{{ v.rusage|json_format }}</pre></td> -->
            <td>{{ v.clock }}</td><td>{{ v.pid }}</td>
            <td>{{ v.total }}</td>
            <td>{{ v.pool.processes|length }}</td>
            <td><a href="/ansible/celery/{{ k }}">点击详情</a></td>
            <td>
                <div class="form-inline">
                    <div class="form-group">
                      <input class="form-control" name="{{ k }}">
                      <button type="submit" class="btn btn-default grow">增加</button>
                      <button type="submit" class="btn btn-default shrink">减少</button>
                  </div>
                </div>
            </td>
        </tr>    
        {% endfor %}

      </table>
        {% if data|length == 0 %}
            <p>未检测到 Celery 节点 </p>
        {% endif %}


</div>

<script type="text/javascript">
  $('.grow').click(function(){
      node = $('input', $(this).parent()[0])[0]
      node_name = node.name
      num = node.value
      $.ajax({
          url: "",
          data: {node_name: node_name, num: num, opt:'grow'},
          type: "POST",
          success: function(data){
              alert(data.msg)
          }
      })
  })
  $('.shrink').click(function(){
      node = $('input', $(this).parent()[0])[0]
      node_name = node.name
      num = node.value
      $.ajax({
          url: "",
          data: {node_name: node_name, num: num, opt:'shrink'},
          type: "POST",
          success: function(data){
              console.log(data)
              alert(data.msg)
          }
      })
  })


</script>
{% endblock %}